define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/dividend',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
              
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'group.name', title: __('Group') },
                        { field: 'puser.nickname', title: __('推荐人'), operate: 'LIKE' },
                        { field: 'nickname', title: __('Nickname'), operate: 'LIKE' },
                        { field: 'mobile', title: __('Mobile'), operate: 'LIKE' },
                        { field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        { field: 'score', title: __('Score'), operate: false, sortable: true },
                        { field: 'money', title: __('Money'), operate: false, sortable: true },
                        { field: 'contribution', title: __('贡献值'), operate: false, sortable: true },
                        { field: 'xf_gold', title: __('消费共享金'), operate: false, sortable: true },
                        { field: 'tg_gold', title: __('推广共享金'), operate: false, sortable: true },
                        { field: 'real', title: __('是否实名'), formatter: Table.api.formatter.label, searchList: { 0: __('未实名'), 1: __('已实名'), 2: __('实名失败') } },
                        { field: 'state', title: __('状态'), formatter: Table.api.formatter.status, searchList: { 0: __('冻结'), 1: __('Normal') } },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'moneylog',
                                    title: '余额明细',
                                    text: '余额明细',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'user/moneylog/index',//接口地址 控制器名/方法名
                                },
                                {
                                    name: 'scorelog',
                                    title: '积分明细',
                                    text: '积分明细',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'user/scorelog/index',//接口地址 控制器名/方法名
                                },
                                {
                                    name: 'scorelog',
                                    title: '消费共享金明细',
                                    text: '消费共享金明细',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'gold_log/index?type=xf',//接口地址 控制器名/方法名
                                },
                                {
                                    name: 'scorelog',
                                    title: '推广共享金明细',
                                    text: '推广共享金明细',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'gold_log/index?type=tg',//接口地址 控制器名/方法名
                                },
                            ]

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        dividend: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});